/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package org.dromara.setting.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.setting.domain.SettingConfigItem;
import org.dromara.setting.domain.bo.SettingConfigItemBo;
import org.dromara.setting.domain.vo.*;
import org.dromara.setting.enums.SettingAllEnums;
import org.dromara.setting.enums.SettingAllEnums.*;
import org.dromara.setting.mapper.SettingConfigItemMapper;
import org.dromara.setting.service.ISettingConfigGroupService;
import org.dromara.setting.service.ISettingConfigItemService;
import org.dromara.system.domain.bo.SysDictDataBo;
import org.dromara.system.domain.vo.SysDictDataVo;
import org.dromara.system.service.ISysDictDataService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 配置项Service业务层处理
 *
 * @author LXK-RY5
 * @date 2024-08-10
 */
@RequiredArgsConstructor
@Service
public class SettingConfigItemServiceImpl implements ISettingConfigItemService {

    private final SettingConfigItemMapper baseMapper;

    private final ISettingConfigGroupService settingConfigGroupService;

    private final ISysDictDataService sysDictDataService;

    @Override
    public boolean existByKey(Long groupId, String key) {
        LambdaQueryWrapper<SettingConfigItem> lqw = Wrappers.lambdaQuery();
        lqw.eq(SettingConfigItem::getKey, key);
        lqw.eq(SettingConfigItem::getConfigGroupId, groupId);
        return baseMapper.exists(lqw);
    }

    @Override
    public SettingConfigItemVo queryByGroupIdAndKey(Long groupId, String key) {
        LambdaQueryWrapper<SettingConfigItem> lqw = Wrappers.lambdaQuery();
        lqw.eq(SettingConfigItem::getKey, key);
        lqw.eq(SettingConfigItem::getConfigGroupId, groupId);
        return baseMapper.selectVoOne(lqw);
    }


    @Override
    public SettingConfigItemVo queryByKey(String key) {
        LambdaQueryWrapper<SettingConfigItem> lqw = Wrappers.lambdaQuery();
        lqw.in(SettingConfigItem::getKey, key);
        return baseMapper.selectVoOne(lqw);
    }

    /**
     * 查询IdList配置项Map
     */
    @Override
    public Map<Long, SettingConfigItemVo> queryMapByIdList(List<Long> idList) {
        return this.queryByIdList(idList).stream().collect(Collectors.toMap(SettingConfigItemVo::getId, v -> v));
    }

    /**
     * 查询配置项Map
     */
    @Override
    public Map<Long, SettingConfigItemVo> queryMap(SettingConfigItemBo bo) {
        return this.queryList(bo).stream().collect(Collectors.toMap(SettingConfigItemVo::getId, v -> v));
    }

    /**
     * 查询配置项IdList
     */
    @Override
    public List<SettingConfigItemVo> queryByIdList(List<Long> idList) {
        if (CollUtil.isEmpty(idList)) {
            return CollUtil.newArrayList();
        }
        LambdaQueryWrapper<SettingConfigItem> lqw = Wrappers.lambdaQuery();
        lqw.in(SettingConfigItem::getId, idList);
        return baseMapper.selectVoList(lqw);
    }

    /**
     * 查询配置项
     *
     * @param id 主键
     * @return 配置项
     */
    @Override
    public SettingConfigItemVo queryById(Long id) {
        return baseMapper.selectVoById(id);
    }

    /**
     * 分页查询配置项列表
     *
     * @param bo        查询条件
     * @param pageQuery 分页参数
     * @return 配置项分页列表
     */
    @Override
    public TableDataInfo<SettingConfigItemVo> queryPageList(SettingConfigItemBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(bo);
        Page<SettingConfigItemVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询符合条件的配置项列表
     *
     * @param bo 查询条件
     * @return 配置项列表
     */
    @Override
    public List<SettingConfigItemVo> queryList(SettingConfigItemBo bo) {
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<SettingConfigItem> buildQueryWrapper(SettingConfigItemBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<SettingConfigItem> lqw = Wrappers.lambdaQuery();
        lqw.orderByDesc(SettingConfigItem::getId);
        lqw.between(params.get("beginCreateTime") != null && params.get("endCreateTime") != null,
            SettingConfigItem::getCreateTime, params.get("beginCreateTime"), params.get("endCreateTime"));
        lqw.between(params.get("beginUpdateTime") != null && params.get("endUpdateTime") != null,
            SettingConfigItem::getUpdateTime, params.get("beginUpdateTime"), params.get("endUpdateTime"));
        lqw.like(StringUtils.isNotBlank(bo.getName()), SettingConfigItem::getName, bo.getName());
        lqw.eq(StringUtils.isNotBlank(bo.getKey()), SettingConfigItem::getKey, bo.getKey());
        lqw.eq(StringUtils.isNotBlank(bo.getValue()), SettingConfigItem::getValue, bo.getValue());
        lqw.eq(bo.getSortNum() != null, SettingConfigItem::getSortNum, bo.getSortNum());
        lqw.eq(StringUtils.isNotBlank(bo.getValueInputType()), SettingConfigItem::getValueInputType, bo.getValueInputType());
        lqw.eq(bo.getConfigGroupId() != null, SettingConfigItem::getConfigGroupId, bo.getConfigGroupId());
        return lqw;
    }

    /**
     * 新增配置项
     *
     * @param bo 配置项
     * @return 是否新增成功
     */
    @Override
    public Boolean insertByBo(SettingConfigItemBo bo) {
        SettingConfigItem add = MapstructUtils.convert(bo, SettingConfigItem.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改配置项
     *
     * @param bo 配置项
     * @return 是否修改成功
     */
    @Override
    public Boolean updateByBo(SettingConfigItemBo bo) {
        SettingConfigItem update = MapstructUtils.convert(bo, SettingConfigItem.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(SettingConfigItem entity) {
    }

    /**
     * 校验并批量删除配置项信息
     *
     * @param ids     待删除的主键集合
     * @param isValid 是否进行有效性校验
     * @return 是否删除成功
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
        }
        return baseMapper.deleteByIds(ids) > 0;
    }

    @Override
    public ChannelOaVo wxMpDetail() {

        ChannelOaVo vo = new ChannelOaVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(WxMpAppConfigEnums.WX_MP);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setName(map.get(WxMpAppConfigEnums.NAME.getKey()));
        vo.setPrimaryId(map.get(WxMpAppConfigEnums.PRIMARY_ID.getKey()));
        vo.setAppId(map.get(WxMpAppConfigEnums.APP_ID.getKey()));
        vo.setAppSecret(map.get(WxMpAppConfigEnums.APP_SECRET.getKey()));
        vo.setQrCode(map.get(WxMpAppConfigEnums.QR_CODE.getKey()));
        vo.setUrl(map.get(WxMpAppConfigEnums.URL.getKey()));
        vo.setToken(map.get(WxMpAppConfigEnums.TOKEN.getKey()));
        vo.setEncodingAesKey(map.get(WxMpAppConfigEnums.ENCODING_AES_KEY.getKey()));
        SettingConfigItemVo encryptionType = map.get(WxMpAppConfigEnums.ENCRYPTION_TYPE.getKey());
        encryptionType.setSysDicList(getDic(WxMpAppConfigEnums.WX_MP, StringUtils.toUnderScoreCase(WxMpAppConfigEnums.ENCRYPTION_TYPE.getKey())));
        vo.setEncryptionType(encryptionType);
        vo.setBusinessDomain(map.get(WxMpAppConfigEnums.BUSINESS_DOMAIN.getKey()));
        vo.setJsDomain(map.get(WxMpAppConfigEnums.JS_DOMAIN.getKey()));
        vo.setWebDomain(map.get(WxMpAppConfigEnums.WEB_DOMAIN.getKey()));
        return vo;
    }

    @Override
    public ChannelMpVo wxMiniDetail() {

        ChannelMpVo vo = new ChannelMpVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(WxMiniAppItemEnums.WX_MINI_APP);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setName(map.get(WxMiniAppItemEnums.NAME.getKey()));
        vo.setPrimaryId(map.get(WxMiniAppItemEnums.PRIMARY_ID.getKey()));
        vo.setAppId(map.get(WxMiniAppItemEnums.APP_ID.getKey()));
        vo.setAppSecret(map.get(WxMiniAppItemEnums.APP_SECRET.getKey()));
        vo.setQrCode(map.get(WxMiniAppItemEnums.QR_CODE.getKey()));
        vo.setRequestDomain(map.get(WxMiniAppItemEnums.REQUEST_DOMAIN.getKey()));
        vo.setSocketDomain(map.get(WxMiniAppItemEnums.SOCKET_DOMAIN.getKey()));
        vo.setUploadFileDomain(map.get(WxMiniAppItemEnums.UPLOAD_FILE_DOMAIN.getKey()));
        vo.setDownloadFileDomain(map.get(WxMiniAppItemEnums.DOWNLOAD_FILE_DOMAIN.getKey()));
        vo.setUdpDomain(map.get(WxMiniAppItemEnums.UDP_DOMAIN.getKey()));
        vo.setTcpDomain(map.get(WxMiniAppItemEnums.TCP_DOMAIN.getKey()));
        vo.setBusinessDomain(map.get(WxMiniAppItemEnums.BUSINESS_DOMAIN.getKey()));
        return vo;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean bulkEdit(List<SettingConfigItemBo> bo) {
        List<Long> idList = bo.stream().map(SettingConfigItemBo::getId).collect(Collectors.toList());
        Map<Long, SettingConfigItemVo> map = queryMapByIdList(idList);
        if (CollUtil.isEmpty(map)) {
            throw new ServiceException("修改的配置不存在");
        }
        List<SettingConfigItem> updateList = new ArrayList<>(bo.size());
        for (SettingConfigItemBo item : bo) {
            SettingConfigItemVo vo = map.get(item.getId());
            if (item.getId() == null || vo == null) {
                throw new ServiceException(StrUtil.format("修改的配置不存在,id:{}", item.getId()));
            }
            if (!item.getConfigGroupId().equals(vo.getConfigGroupId())) {
                throw new ServiceException(StrUtil.format("配置组无法修改,configGroupId:{}", item.getConfigGroupId()));
            }
            SettingConfigItem up = MapstructUtils.convert(item, SettingConfigItem.class);
            updateList.add(up);
        }
        if (CollUtil.isEmpty(updateList)) {
            throw new ServiceException("暂无数据可修改");
        }
        return baseMapper.updateBatchById(updateList);
    }

    @Override
    public ChannelYueVo yueDetail() {

        ChannelYueVo vo = new ChannelYueVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(BalancePayEnums.YUE);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setName(map.get(BalancePayEnums.NAME.getKey()));
        vo.setIcon(map.get(BalancePayEnums.ICON.getKey()));
        vo.setSort(map.get(BalancePayEnums.SORT.getKey()));
        SettingConfigItemVo state = map.get(BalancePayEnums.STATE.getKey());
        state.setSysDicList(getDic(BalancePayEnums.YUE, BalancePayEnums.STATE.getKey()));
        vo.setState(state);
        return vo;
    }

    @Override
    public ChannelAllVo allDetail() {

        ChannelAllVo vo = new ChannelAllVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(AliPayEnums.ALL_PAY);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setName(map.get(AliPayEnums.NAME.getKey()));
        vo.setIcon(map.get(AliPayEnums.ICON.getKey()));

        SettingConfigItemVo payMode = map.get(AliPayEnums.PAY_MODE.getKey());
        payMode.setSysDicList(getDic(AliPayEnums.ALL_PAY, AliPayEnums.PAY_MODE.getKey()));
        vo.setPayMode(payMode);
        SettingConfigItemVo mchType = map.get(AliPayEnums.MCH_TYPE.getKey());
        mchType.setSysDicList(getDic(AliPayEnums.ALL_PAY, AliPayEnums.MCH_TYPE.getKey()));
        vo.setMchType(mchType);

        vo.setAliAppId(map.get(AliPayEnums.ALI_APP_ID.getKey()));
        vo.setAliPrivateKey(map.get(AliPayEnums.ALI_PRIVATE_KEY.getKey()));
        vo.setAliPayPublicKey(map.get(AliPayEnums.ALI_PAY_PUBLIC_KEY.getKey()));
        vo.setSort(map.get(AliPayEnums.SORT.getKey()));

        SettingConfigItemVo state = map.get(AliPayEnums.STATE.getKey());
        state.setSysDicList(getDic(AliPayEnums.ALL_PAY, AliPayEnums.STATE.getKey()));
        vo.setState(state);

        vo.setAliAppCertPath(map.get(SettingAllEnums.AliPayEnums.ALI_APP_CERT_PATH.getKey()));
        vo.setAliPayCertPath(map.get(SettingAllEnums.AliPayEnums.ALI_PAY_CERT_PATH.getKey()));
        vo.setServerUrl(map.get(SettingAllEnums.AliPayEnums.SERVER_URL.getKey()));
        vo.setAliPayRootCertPath(map.get(SettingAllEnums.AliPayEnums.ALI_PAY_ROOT_CERT_PATH.getKey()));
        vo.setAliNotifyUrl(map.get(SettingAllEnums.AliPayEnums.ALI_NOTIFY_URL.getKey()));
        vo.setAliRefundUrl(map.get(SettingAllEnums.AliPayEnums.ALI_REFUND_URL.getKey()));
        return vo;
    }

    @Override
    public ChannelWXPayVo wxPayDetail() {
        ChannelWXPayVo vo = new ChannelWXPayVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(WxPayEnums.WX_PAY);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setName(map.get(WxPayEnums.NAME.getKey()));
        vo.setIcon(map.get(WxPayEnums.ICON.getKey()));

        SettingConfigItemVo wxVersion = map.get(WxPayEnums.WX_VERSION.getKey());
        wxVersion.setSysDicList(getDic(WxPayEnums.WX_PAY, WxPayEnums.WX_VERSION.getKey()));
        vo.setWxVersion(wxVersion);

        SettingConfigItemVo mchType = map.get(WxPayEnums.MCH_TYPE.getKey());
        mchType.setSysDicList(getDic(WxPayEnums.WX_PAY, WxPayEnums.MCH_TYPE.getKey()));
        vo.setMchType(mchType);

        vo.setSort(map.get(WxPayEnums.SORT.getKey()));
        SettingConfigItemVo state = map.get(WxPayEnums.STATE.getKey());
        state.setSysDicList(getDic(WxPayEnums.WX_PAY, WxPayEnums.STATE.getKey()));
        vo.setState(state);

        vo.setSlAppId(map.get(SettingAllEnums.WxPayEnums.SLAPPID.getKey()));
        vo.setSlMchId(map.get(SettingAllEnums.WxPayEnums.SLMCHID.getKey()));
        vo.setAppId(map.get(SettingAllEnums.WxPayEnums.APPID.getKey()));
        vo.setCertPath(map.get(SettingAllEnums.WxPayEnums.CERT_PATH.getKey()));
        vo.setCertP12Path(map.get(SettingAllEnums.WxPayEnums.CERT_P12_PATH.getKey()));
        vo.setKeyPath(map.get(SettingAllEnums.WxPayEnums.KEY_PATH.getKey()));
        vo.setPartnerKey(map.get(SettingAllEnums.WxPayEnums.PARTNER_KEY.getKey()));
        vo.setApiKey(map.get(SettingAllEnums.WxPayEnums.API_KEY.getKey()));
        vo.setApiKey3(map.get(SettingAllEnums.WxPayEnums.API_KEY3.getKey()));
        vo.setMchId(map.get(SettingAllEnums.WxPayEnums.MCH_ID.getKey()));
        vo.setDomain(map.get(SettingAllEnums.WxPayEnums.DOMAIN.getKey()));
        vo.setWxPayNotifyUrl(map.get(SettingAllEnums.WxPayEnums.WX_PAY_NOTIFY_URL.getKey()));
        vo.setWxRefundNotifyUrl(map.get(SettingAllEnums.WxPayEnums.WX_REFUND_NOTIFY_URL.getKey()));
        return vo;
    }

    @Override
    public AgreementVo userAgreement() {
        AgreementVo vo = new AgreementVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(AgreementEnums.AGREEMENT);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setUserAgreement(map.get(AgreementEnums.USER_AGREEMENT.getKey()));
        vo.setPrivacyPolicy(map.get(AgreementEnums.PRIVACY_POLICY.getKey()));
        vo.setAboutApp(map.get(AgreementEnums.ABOUT_APP.getKey()));
        return vo;
    }

    @Override
    public SettingConfigItemVo selectValueByKey(String key1, String key2) {
        SettingConfigItemVo vo = new SettingConfigItemVo();
        vo.setValue(StringUtils.EMPTY);
        //根据租户id查询
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(key1);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        SettingConfigItemBo bo = new SettingConfigItemBo();
        bo.setConfigGroupId(queryByType.getId());
        bo.setKey(key2);
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(bo);
        SettingConfigItemVo resp = baseMapper.selectVoOne(lqw);
        if (ObjectUtil.isNull(resp)) {
            return vo;
        }
        return resp;
    }

    @Override
    public Boolean payIsShow(Long id) {
        SettingConfigItemBo bo = new SettingConfigItemBo();
        bo.setConfigGroupId(id);
        //余额、微信、支付宝状态一样
        bo.setKey(WxPayEnums.STATE.getKey());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(bo);
        SettingConfigItemVo vo = baseMapper.selectVoOne(lqw);
        if (ObjectUtil.isNull(vo)) {
            return Boolean.TRUE;
        }
        String state = vo.getValue().equals(String.valueOf(BigDecimal.ZERO)) ? "1" : "0";
        SettingConfigItem update = MapstructUtils.convert(vo, SettingConfigItem.class);
        update.setValue(state);
        return baseMapper.updateById(update) > 0;
    }

    @Override
    public LxkOpenApiVo lxkOpenApiDetail() {
        LxkOpenApiVo vo = new LxkOpenApiVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(LxkOpenApiEnums.LXK_OPEN_API);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setSecretKey(map.get(LxkOpenApiEnums.LXK_SECRET_KEY.getKey()));
        vo.setAccessKey(map.get(LxkOpenApiEnums.LXK_ACCESS_KEY.getKey()));
        vo.setSmsSignId(map.get(LxkOpenApiEnums.SMS_SIGN_ID.getKey()));
        vo.setTemplateId(map.get(LxkOpenApiEnums.TEMPLATE_ID.getKey()));
        return vo;
    }

    @Override
    public LxkOmsOrderVo omsOrderDetail() {
        LxkOmsOrderVo vo = new LxkOmsOrderVo();
        SettingConfigItemBo itemBo = new SettingConfigItemBo();
        SettingConfigGroupVo queryByType = settingConfigGroupService.queryByType(OmsOrderEnums.LXK_OMS_ORDER);
        if (ObjectUtil.isNull(queryByType)) {
            return vo;
        }
        itemBo.setConfigGroupId(queryByType.getId());
        LambdaQueryWrapper<SettingConfigItem> lqw = buildQueryWrapper(itemBo);
        List<SettingConfigItemVo> list = baseMapper.selectVoList(lqw);
        if (CollUtil.isEmpty(list)) {
            return vo;
        }
        Map<String, SettingConfigItemVo> map = list.stream().collect(Collectors.toMap(SettingConfigItemVo::getKey, v -> v));
        vo.setApiId(map.get(OmsOrderEnums.API_ID.getKey()));
        vo.setReceiveExpireTime(map.get(OmsOrderEnums.RECEIVE_EXPIRE_TIME.getKey()));
        vo.setPayExpireTime(map.get(OmsOrderEnums.PAY_EXPIRE_TIME.getKey()));
        vo.setCommentExpireTime(map.get(OmsOrderEnums.COMMENT_EXPIRE_TIME.getKey()));
        return vo;
    }

    /**
     * 更具字典类型和字典键获取字典值
     *
     * @param key1 项目组key
     * @param key2 配置项key
     * @return
     */
    private List<SysDictDataVo> getDic(String key1, String key2) {
        SysDictDataBo mDic = new SysDictDataBo();
        mDic.setDictType(StrUtil.format("{}_{}", key1, key2).toLowerCase());
        return sysDictDataService.selectDictDataList(mDic);
    }

}
